﻿using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using PersonalAccounting.Business;

namespace PersonalAccounting.Controls
{
    public partial class MonedaComboBox : ComboBox
    {

        public MonedaComboBox()
        {
            InitializeComponent();
        }

        public MonedaComboBox(Container container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public void CargarMonedas()
        {
            MonedaFacade facade = new MonedaFacade();

            Items.Clear();
            foreach (Moneda moneda in facade.GetAll())
                Items.Add(moneda);

            if (Items.Count > 0)
                SelectedIndex = 0;
        }

        public Moneda Value
        {
            get { return (Moneda)SelectedItem; }
            set
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    Moneda tmp = (Moneda)Items[i];
                    if (tmp.Codigo == value.Codigo)
                    {
                        SelectedIndex = i;
                        break;
                    }
                }
            }
        }
    }
}